package org.bee.tl.core;

import org.antlr.runtime.Token;
import org.antlr.runtime.tree.CommonTree;
import org.bee.tl.core.compile.PreCompileException;

/**
 * antlr 节点，每个节点提供额外的俩个类型，一个是typeClass，指示该节点对象类型，一个是cached，用于节点运行
 * 时可缓存的值，如文本节点代表的字符串。
 * 
 * @author joelli
 * @see TypeTable
 * 
 */
public class BeeCommonNodeTree extends CommonTree {
	private TypeClass typeClass;
	private Object cached = null;

	public BeeCommonNodeTree() {
		// TODO Auto-generated constructor stub
	}

	public BeeCommonNodeTree(CommonTree node) {
		super(node);
		// TODO Auto-generated constructor stub
	}

	public BeeCommonNodeTree(Token t) {
		super(t);
		// TODO Auto-generated constructor stub
	}

	public TypeClass getTypeClass() {
		if (typeClass == null) {
			typeClass = new TypeClass();
		}
		return typeClass;
	}

	public void setTypeClass(TypeClass typeClass) {
		this.typeClass = typeClass;
	}

	public void setExpType(Class c) {
		if (c == null) {
			throw new PreCompileException("预编译bug，未能判断表达式类型"
					+ this.getToken().getText() + " "
					+ this.getToken().getLine());
		}
		this.typeClass = new TypeClass(c);
	}

	public Class getExpType() {
		if (this.typeClass == null)
			return null;
		else
			return this.typeClass.getRawType();
	}

	public Object getCached() {
		return cached;
	}

	public void setCached(Object cached) {
		this.cached = cached;
	}

}
